package com.xxx.config.exception.support;

import com.fasterxml.jackson.databind.JsonMappingException;
import com.xxx.config.exception.ErrorResponseStatusCode;
import com.xxx.config.exception.GenExceptCode;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;


/**
 * Json转换错误解析
 *
 * @version 1.0
 * @since 1.0
 */
public class JsonMapperExceptionSupport implements ExceptionMapper<JsonMappingException> {
    @Override
    public Response toResponse(JsonMappingException e) {
        String json = "{" + "code" + ":\"" + GenExceptCode.Request_Param.name() + "\"," + "msg" + ":\"" + e.getMessage() + "\"}";
        return Response.status(ErrorResponseStatusCode.SERVICE_ERROR).entity(json).type(MediaType.APPLICATION_JSON).build();
    }
}
